package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import controlador.BussinesDelegate;
import dto.EmpleadoDTO;

public class EmpleadoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public EmpleadoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 try {
	        
	        	 if(request.getParameter("action").equals("validarEmpleado")){
	        		
	        		String usuario = request.getParameter("usuario");
	        		String password = request.getParameter("password");
	        		String tipo = request.getParameter("tipo");
	        		EmpleadoDTO e = BussinesDelegate.getInstancia().validarUsuario(usuario, password, tipo);
	        		
	        		RequestDispatcher dispatcher = null;
	        		
        			if(e!= null){
	        			request.setAttribute("cliente", e);
	        			dispatcher=request.getRequestDispatcher("/.jsp");
	        		}else{
	        			dispatcher=request.getRequestDispatcher("/MensajeValidacion.jsp");
	        			HttpSession session = request.getSession();
	 	                session.setAttribute("mensaje", "El Usuario ingresado no existe.");
	 	                session.setAttribute("usuario", usuario);
	        		}
 
	        		dispatcher.forward(request, response);
	        	}
	        	
	        } catch(Exception e){
	            e.printStackTrace();
	        }
	}

}
